package thread;

/**
 * 当一个静态方法上使用synchronized后,那么该方法
 */
public class SyncDemo03 {
    public static void main(String[] args) {
//        Foo f1 = new Foo();
//        Foo f2 = new Foo();
        Thread t1 = new Thread(){
            @Override
            public void run() {
                Foo.dosome();
//                f1.dosome();
            }
        };

        Thread t2 = new Thread(){
            @Override
            public void run() {
                Foo.dosome();
//                f2.dosome();
            }
        };
        t1.start();
        t2.start();
    }
}

class Foo{
//    public synchronized static void dosome(){
    public static void dosome(){
        synchronized (Foo.class) {
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在执行dosome方法");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName()+"执行dosome方法完毕");
        }
    }
}
